package com.liu.es.controller;

import com.liu.es.services.impl.GoodsServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/search")
@Slf4j
public class SearchGoodsController {
    @Autowired
    private GoodsServiceImpl goodsService;

    /**
     * 查询方法，将es中的数据全部查询出来后用map封装
     * 最后放到ModelMap中返回给前端
     * @param param
     * @param modelMap
     * @return
     * @throws Exception
     */
    @GetMapping("/searchGoods")
    public String searchGoods(@RequestParam Map<String,Object> param, ModelMap modelMap) throws Exception {
        List<Map<String,Object>> goodsMapList = goodsService.search(param);
        modelMap.put("goodsMapList", goodsMapList);
        return "searchList";
    }
}
